#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct {
    int* a;
    int front;
    int back;
    int cap;
} MyCircularQueue;

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    return (obj->back + 1) % (obj->cap + 1) == obj->front;
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    return obj->front == obj->back;
}

MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    if (obj == NULL)
    {
        perror("malloc failure");
        exit(-1);
    }
    obj->a = (int*)malloc(sizeof(int) * (k + 1));
    obj->front = 0;
    obj->back = 0;
    obj->cap = k;
    return obj;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (myCircularQueueIsFull(obj))
        return false;
    obj->a[obj->back] = value;
    obj->back++;
    obj->back %= (obj->cap + 1);
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return false;
    obj->front++;
    obj->front %= (obj->cap + 1);
    return true;
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;

    return obj->a[obj->front];
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;

    return obj->a[(obj->back + obj->cap) % (obj->cap + 1)];
}


void myCircularQueueFree(MyCircularQueue* obj) {
    free(obj->a);
    free(obj);
}


int main()
{
    MyCircularQueue* obj = myCircularQueueCreate(4);
    bool param_1 = myCircularQueueEnQueue(obj, 6);
    bool param_2 = myCircularQueueDeQueue(obj);
    int param_3 = myCircularQueueFront(obj);
    int param_4 = myCircularQueueRear(obj);
    bool param_5 = myCircularQueueIsEmpty(obj);
    bool param_6 = myCircularQueueIsFull(obj);
    myCircularQueueFree(obj);
    return 0;
}